#pragma once
#include <mutex>
#include <string>
#include <curl/curl.h>
#include <atomic>
#include <unordered_map>
#include <memory>
namespace CppWinApi::HttpClients
{
    class HttpHeader
    {
    public:
        HttpHeader();

        std::string &operator[](const std::string &key);
        void Remove(const std::string &key);
        curl_slist *ToCurlHeaders();

    private:
        struct CurlSlistDeleter
        {
            // 自定义的一个删除器，用来删除 curl_slist
            // 重载 () 运算符
            void operator()(curl_slist *list) const { curl_slist_free_all(list); }
        };
        using CurlSlistPtr = std::unique_ptr<curl_slist, CurlSlistDeleter>;
        std::mutex objLock;
        std::unordered_map<std::string, std::string> headers;
        CurlSlistPtr curlHeaders;
        bool headerIsChanged = true;
    };
}
